const app = require('http').createServer()
const io = require('socket.io')(app);
const port = 8001
let ClientCount = 0;
app.listen(port);

io.on('connection',  (socket)=>{
    ClientCount++
    socket.nickname = 'user'+ ClientCount
    io.emit('enter', {user:socket.nickname, tag:'come in'});

    socket.on('message', (data)=>{
        io.emit('message', {user:socket.nickname, data})
    });

    socket.on('disconnect', ()=>{
        io.emit('leave', {user:socket.nickname, tag:'left'})
    });
});

console.log(`websocket is listen to port:${port}`)
